package com.lightsaber.trade.as.dao.planning;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Query;
import org.springframework.stereotype.Component;

import com.lightsaber.trade.as.entity.planning.ResourceGroup;
import com.lightsaber.trade.core.dao.BaseDao;

@Component
public class ResourceGroupDao extends BaseDao<ResourceGroup, String> {

    public List<ResourceGroup> findByLeve3IdAndProgrammePlanningId(final String level3PlanningId,
            final String programmePlanningItemId) {
        eq("level3Planning.id", level3PlanningId);
        eq("programmePlanningItem.id", programmePlanningItemId);
        return list();
    }

    public void deleteByLeve3IdAndProgrammePlanningId(final String level3PlanningId,
            final String programmePlanningItemId) {
        String hql = "delete from ResourceGroup where level3Planning.id=:level3PlanningId and programmePlanningItem.id=:programmePlanningItemId";
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("level3PlanningId", level3PlanningId);
        map.put("programmePlanningItemId", programmePlanningItemId);
        Query q = this.createQuery(hql, map);
        q.executeUpdate();
    }
}
